
/*页面input的样式，包括聚焦到第一个input*/
function textStyle() {
	var obj = document.getElementsByTagName("input");
	var j = 0;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].type == "hidden") {
			continue;
		}
		if (i == 0) {
			obj[i].focus();
		}
		if ((obj[i].type == "text" || obj[i].type == "password") && (obj[i].name != "loginName" && obj[i].name != "loginPassword" && obj[i].name != "loginCode")) {
			if (j == 0) {
				obj[i].focus();
			}
			obj[i].style.width = "162px";
			obj[i].style.height = "21px";
			obj[i].style.border = "1px solid #aaa";
			j++;
		}
		reSetBGColor(obj[i]);
	}
}
function checkIdCard(idcard) {//正确返回true，错误返回false
	var year = parseInt(idcard.substr(6, 4), 10);
	var month = parseInt(idcard.substr(10, 2), 10);
	var date = parseInt(idcard.substr(12, 2), 10);
	if (idcard == "") {
		return false;
	} else {
		if (idcard.length < 18) {
			return false;
		} else {
			if (year < 1909 || year > 2000) {
				return false;
			} else {
				if (month < 1 || month > 12) {
					return false;
				} else {
					if (date < 1 || date > 31) {
						return false;
					}
				}
			}
		}
	}
	return true;
}
function setBGColor(obj) {
	obj.style.background = "red";
	obj.focus();
}
function reSetBGColor(obj) {
	obj.style.background = "";
}
function noSpace() {
	if (event.keyCode == 32) {
		event.returnValue = false;
	}
}
function noPast() {
	if (event.ctrlKey && event.keyCode == 86) {
		event.returnValue = false;
	}
}
function noRightMouse(obj) {
	if (event.button == 2 || event.button == 3) {
		obj.onMouseUp = null;
	}
}
function onlyUserName() {
	if (event.shiftKey && (event.keyCode >= 48 && event.keyCode <= 57)) {
		event.returnValue = false;
	}
}
function removeSpecial(obj) {
	obj.value = obj.value.replace(/[^\w-.]/g, "");
}
/*以前的方法，要删除*/
/*
function onlyNumber() {
	if (event.shiftKey) {
		event.returnValue = false;
	}
	if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) && event.keyCode != 8 && event.keyCode != 37 && event.keyCode != 39 && event.keyCode != 9 && event.keyCode != 46) {
		event.returnValue = false;
	}
}
*/
function onlyNumber(obj) {
//	if (obj.value == "" && (event.keyCode == 48 || event.keyCode == 96)) {
//		event.returnValue = false;
//	}
	if (event.shiftKey) {
		event.returnValue = false;
	}
	if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) && event.keyCode != 8 && event.keyCode != 37 && event.keyCode != 39 && event.keyCode != 9 && event.keyCode != 46) {
		event.returnValue = false;
	}
}
function onlyMoney(obj) {
	if (event.shiftKey) {
		event.returnValue = false;
	}
	if (obj.value == "" && (event.keyCode == 190 || event.keyCode == 110)) {
		event.returnValue = false;
	}
	var objs = obj.value.split(".");
	if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) && event.keyCode != 8 && event.keyCode != 190 && event.keyCode != 110 && event.keyCode != 37 && event.keyCode != 39 && event.keyCode != 9 && event.keyCode != 46) {
		event.returnValue = false;
	} else {
		if ((objs.length == 2 || obj.value == "") && (event.keyCode == 190 || event.keyCode == 110) && event.keyCode != 9 && event.keyCode != 46) {
			event.returnValue = false;
		} else {
			if (objs.length == 2 && objs[1].length >= 2 && event.keyCode != 8 && event.keyCode != 9 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) {
				event.returnValue = false;
			}
		}
	}
}
function onlyMoney(obj, dot) {
	if (event.shiftKey) {
		event.returnValue = false;
	}
	if (obj.value == "" && (event.keyCode == 190 || event.keyCode == 110)) {
		event.returnValue = false;
	}
	var objs = obj.value.split(".");
	if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) && event.keyCode != 8 && event.keyCode != 190 && event.keyCode != 110 && event.keyCode != 37 && event.keyCode != 39 && event.keyCode != 9 && event.keyCode != 46) {
		event.returnValue = false;
	} else {
		if ((objs.length == 2 || obj.value == "") && (event.keyCode == 190 || event.keyCode == 110) && event.keyCode != 9 && event.keyCode != 46) {
			event.returnValue = false;
		} else {
			if (objs.length == 2 && objs[1].length >= dot && event.keyCode != 8 && event.keyCode != 9 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) {
				event.returnValue = false;
			}
		}
	}
}
function onlyPhoneNumber(obj) {
	if (event.shiftKey) {
		event.returnValue = false;
	}
	var objs = obj.value.split("-");
	if ((objs.length == 2 || obj.value == "") && (event.keyCode == 189 || event.keyCode == 109) && event.keyCode != 9 && event.keyCode != 46) {
		event.returnValue = false;
	}
	if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) && event.keyCode != 8 && event.keyCode != 37 && event.keyCode != 39 && event.keyCode != 189 && event.keyCode != 109 && event.keyCode != 9 && event.keyCode != 46) {
		event.returnValue = false;
	}
}
/*可编辑下拉框的js*/
function comboOnload(inputName) {
	//alert();
	document.getElementById(inputName).value = document.getElementById("comboBox").value;
}
function inputChange(obj) {
	//var comboBox = document.getElementById("comboBox");
}
function selectChange(obj, inputName) {
	document.getElementById(inputName).value = obj.value;
	if (obj.value == "") {
		document.getElementById(inputName).readOnly = false;
	} else {
		document.getElementById(inputName).readOnly = true;
	}
}
/*show or hidden span/div ....*/
function hidden(objName) {
	var objName = document.getElementById(objName);
	objName.style.display = "none";
}
function show(objName) {
	var objName = document.getElementById(objName);
	objName.style.display = "";
}
/*common中的页面的function*/
function formSubmit(formName, action) {
	var f = document.getElementById(formName);
	if (action != "") {
		f.action = action;
	}
	f.submit();
}
/*分页的js*/
function nextPage(currentPage, totalPage, formName, action) {
	//alert(currentPage+"--"+totalPage);
	if (currentPage >= totalPage) {
		return;
	}
	//alert(currentPage+1);
	document.getElementById("toPage").value = (currentPage + 1);
	formSubmit(formName, action);
}
function prePage(currentPage, formName, action) {
	if (currentPage == 1) {
		return;
	}
	document.getElementById("toPage").value = (currentPage - 1);
	formSubmit(formName, action);
}
function firstPage(currentPage, formName, action) {
	if (currentPage == 1) {
		return;
	}
	document.getElementById("toPage").value = 1;
	formSubmit(formName, action);
}
function lastPage(currentPage, totalPage, formName, action) {
	if (currentPage >= totalPage) {
		return;
	}
	document.getElementById("toPage").value = totalPage;
	formSubmit(formName, action);
}
function goToPage(currentPage, totalPage, formName, action) {
	var goPage = document.getElementById("goPage").value;
	//alert(goPage+"<br>"+totalPage+"<br>"+currentPage);
	if (goPage <= 0 || parseInt(goPage) > totalPage || goPage == currentPage) {
		//alert("return");
		return;
	}
	//alert("submit");
	document.getElementById("toPage").value = goPage;
	formSubmit(formName, action);
}
function back(formName, witch, action1, action2) {
	var f = document.getElementById(formName);
	//alert(witch);
	if (witch == "0") {
		f.action = action1;
	} else {
		f.action = action2;
	}
	f.submit();
}
function selectAllCb(obj, cbName) {
	var cbs = document.getElementsByName(cbName);
	for (var i = 0; i < cbs.length; i++) {
		cbs[i].checked = obj.checked;
	}
}
function getAllCb(cbName) {
	var cbs = document.getElementsByName(cbName);
	var rs = "";
	for (var i = 0; i < cbs.length; i++) {
		if (cbs[i].checked == true) {
			rs += "," + cbs[i].value;
		}
	}
	//alert(rs);
	return rs;
}
function deleteTickets(cbName, formName, action) {
	var rs = getAllCb(cbName);
	if (rs == "") {
		return;
	}
	if (confirm("\u60a8\u786e\u8ba4\u8981\u5220\u9664\u8fd9\u4e9b\u6570\u636e\u4e48\uff1f")) {
		var f = document.getElementById(formName);
		f.action = action + "" + rs;
		f.submit();
	}
}

function changeCode(obj,src) {
	//重载验证码
	var timenow = new Date().getTime();
	obj.src = src+"&d=" + timenow;
	/*
	setTimeout(function(){
		obj.src="random.jsp?d="+timenow;
	}
	,20);
	*/
}

function exist(formName, action) {
	if (confirm("您确定要退出么？")) {
		formSubmit(formName, action);
	}
}